﻿using Castle.ActiveRecord;
using Castle.ActiveRecord.Framework;
using Castle.ActiveRecord.Framework.Config;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectZero.Model
{
    public class SessionManager
    {
        private static bool initialized = false;

        public static bool InitializeAR()
        {
            lock (typeof(SessionManager))
            {
                try
                {
                    if (!initialized)
                    {
                        NHibernate.Cfg.Environment.UseReflectionOptimizer = false;
                        ActiveRecordStarter.Initialize(typeof(Cliente).Assembly,
                            (IConfigurationSource)System.Configuration.ConfigurationSettings.GetConfig("activerecord"));
                        initialized = true;
                    }
                }
                catch (Exception)
                {
                    initialized = false;
                }
            }

            return initialized;
        }       
        
    }
}
